package com.cuiweiyou.pipixiaautomator;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class PipixiaListAdapter extends BaseAdapter {
    private List<String> list;

    public PipixiaListAdapter(List<String> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int index, View convertView, ViewGroup viewGroup) {
        ItemHolder holder;
        if (convertView == null) {
            convertView = View.inflate(viewGroup.getContext(), R.layout.item_listview, null);
            holder = new ItemHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.textView);
            convertView.setTag(holder);
        } else {
            holder = (ItemHolder) convertView.getTag();
        }

        String item = list.get(index);
        holder.textView.setText(item);

        return convertView;
    }

    class ItemHolder {
        TextView textView;
    }
}
